<?php

namespace console\migrations;

use console\migrations\Base;

/**
 * Handles the creation of table `{{%ticket_patch}}`.
 */
class M200810053803CreateTicketPatchTable extends Base
{

    protected string $tableName = '{{%ticket_patch}}';
    protected string $tableComment = '';

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable( $this->tableName, [
            'id'        => $this->primaryKey(),
            'ticket_id' => $this->integer( 11 )->notNull(),
            'patch_id'  => $this->integer( 11 )->notNull(),
        ], $this->tableOptions );

        $this->addForeignKey( 'fk-ticket_patch-ticket', $this->tableName, 'ticket_id', '{{%ticket}}', 'id' );
        $this->addForeignKey( 'fk-ticket_patch-patch', $this->tableName, 'patch_id', '{{%patch}}', 'id' );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey( 'fk-ticket_patch-ticket', $this->tableName );
        $this->dropForeignKey( 'fk-ticket_patch-patch', $this->tableName );

        $this->dropTable( '{{%ticket_patch}}' );
    }
}
